package com.sie.service.impl;

import com.sie.mapper.UserManagerMapper;
import com.sie.pojo.UserManager;
import com.sie.service.UserManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
@Service
public class UserManagerServiceImpl implements UserManagerService {

    @Autowired
    private UserManagerMapper userManagerMapper;

    @Override
    public int updateUserManager(UserManager userManager) {
        return userManagerMapper.updateUserManager(userManager);
    }

    @Override
    public int updateStatusById(Integer id) {
        return userManagerMapper.updateStatusById(id);
    }

    @Override
    public int deleteById(Integer id) {
        return userManagerMapper.removeManager(id);
    }

    @Override
    public List<UserManager> selectByForm(String username, String name, Integer status, Date date1, Date date2) {
        return userManagerMapper.selectByForm(username,name,status,date1,date2);
    }

    @Override
    public int removeManager(String ids) {
        /*
        *  id通过“,”拆分
        * */
        String[] split = ids.split(",");
        for (int i = 0; i <split.length ; i++) {
            int code=0;
            int id=Integer.parseInt(split[i]);
            code=userManagerMapper.removeManager(id);
            if (code!=1){
                return 0;
            }
        }
        return 1;
    }

    @Override
    public int addUserManager(UserManager userManager) {
        return userManagerMapper.addUserManager(userManager);
    }

    @Override
    public List<UserManager> findAll() {
        return userManagerMapper.findAll();
    }
}
